package cn.kxlove.zhbj;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.widget.RelativeLayout;

import cn.kxlove.zhbj.common.Common;
import cn.kxlove.zhbj.utils.PrefUtils;

/**
 * 闪屏界面
 * @author kxlove 16/1/27 09:31
 */
public class SplashActivity extends Activity{

    private RelativeLayout rlRoot;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        rlRoot = (RelativeLayout) findViewById(R.id.rl_root);

        RotateAnimation animRotate = new RotateAnimation(0,360,
                Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);

        animRotate.setDuration(1000);

        ScaleAnimation animScale = new ScaleAnimation(0,1,0,1,
                Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);

        animScale.setDuration(1000);

        AlphaAnimation animAlpha = new AlphaAnimation(0,1);

        animAlpha.setDuration(2000);

        AnimationSet animationSet = new AnimationSet(true);
        animationSet.addAnimation(animRotate);
        animationSet.addAnimation(animScale);
        animationSet.addAnimation(animAlpha);

        animationSet.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                boolean isGuideShow = PrefUtils.getBoolean(getApplicationContext(), Common.IS_SHOW_GUIDE, false);

                if(!isGuideShow){
                    startActivity(new Intent(getApplicationContext(),GuideActivity.class));
                }else {
                    startActivity(new Intent(getApplicationContext(),MainActivity.class));
                }

                finish();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
                //动画重复
            }
        });

        rlRoot.setAnimation(animationSet);

    }
}
